<script setup>
  import { ref } from 'vue'
  import { ElMessageBox } from 'element-plus'

  const dialogVisible = ref(false)

  // 当关闭对话框时自动调用该回调函数，询问是否关闭对话框
  const handleClose = (done) => {
    ElMessageBox.confirm('Are you sure to close this dialog?')
      .then(() => {
        done()
      })
      .catch(() => {
        // catch error
      })
  }
</script>

<template>
  <el-button plain @click="dialogVisible = true">
    Click to open the Dialog
  </el-button>

  <el-dialog
    v-model="dialogVisible"
    width="500"
    :before-close="handleClose"> 
    <!-- 头部 -->
    <template #header>
      <h3>Tips</h3>
    </template>
    <!-- 主体 -->
    <template #default>
      <el-form>
        <el-form-item label="账号：">
          <el-input></el-input>
        </el-form-item>
        <el-form-item label="密码：">
          <el-input 
          type="password"
          show-password></el-input>
        </el-form-item>
      </el-form>
    </template>
    <!-- 尾部 -->
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogVisible = false">
          Confirm
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>


<style scoped>

</style>